package com.ruoyi.web.controller.tool;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.JzToursArticle;
import com.ruoyi.system.domain.JzToursBanner;
import com.ruoyi.system.domain.JzToursCategory;
import com.ruoyi.system.domain.JzToursShop;
import com.ruoyi.system.domain.vo.ScenicPointVo;
import com.ruoyi.system.domain.vo.ScenicSpotVo;
import com.ruoyi.system.domain.vo.TourismStrategyVo;
import com.ruoyi.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import oshi.software.os.linux.LinuxFileSystem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("首页管理")
@RestController
@RequestMapping("/front/article")
public class HomePageController extends BaseController {
    @Autowired
    private IJzToursCategoryService jzToursCategoryService;


    @Autowired
    private IJzToursBannerService jzToursBannerService;

    @Autowired
    private IJzToursArticleService jzToursArticleService;


    @Autowired
    private IJzToursShopService jzToursShopService;

@Autowired
    private IFeginOutService feginOutService;
    /**
     * 获取首页banner图配置
     * @return
     */
    @ApiOperation("获取banner图")
    @GetMapping("/getHomeBanner")
    public AjaxResult getHomeBanner(@RequestParam("type") Long type){
        JzToursBanner jzToursBanner=new  JzToursBanner();
    if (type==null) {
        jzToursBanner.setType((long)0);
    }else {
        jzToursBanner.setType(type);
    }
        List<JzToursBanner> list = jzToursBannerService.selectJzToursBannerList(jzToursBanner);
        return AjaxResult.success(list) ;

    }


    /**
     * 获取首页分类信息
     * @return
     */
    @ApiOperation("获取首页分类信息")
    @GetMapping("/getHomeCategory")
    public AjaxResult getHomeCategory(){

        JzToursCategory jzToursCategory=new JzToursCategory();
        List<JzToursCategory> list = jzToursCategoryService.selectJzToursCategoryList(jzToursCategory);

     return AjaxResult.success(list);
    }


    /**
     * 获取首页分类信息
     * @return
     */
    @ApiOperation("获取首页区域介绍")
    @GetMapping("/getHomeIntroduce")
    public AjaxResult getHomeIntroduce(){

        JzToursArticle jzToursArticle=new JzToursArticle();
        jzToursArticle.setCateId((long)1009);
        List<JzToursArticle> list = jzToursArticleService.selectJzToursArticleList(jzToursArticle);

        return AjaxResult.success(list);
    }




    /**
     * 获取首页推荐栏目信息
     * @return
     */
    @ApiOperation("获取首页推荐栏目信息")
    @GetMapping("/getHomeRecommend")
    public AjaxResult getHomeRecommend(){
        JzToursShop jzToursShop=new JzToursShop();
        Map<String,List<JzToursShop>> cateList=new HashMap<>();
       //住宿推荐
        Map<String,List<JzToursShop>> Map=new HashMap<>();
         jzToursShop.setCateId((long)1004);
        List<JzToursShop> list = jzToursShopService.selectJzToursShopList(jzToursShop);
        Map.put("hotel",list);



      //美食推荐

        jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1003);
         list = jzToursShopService.selectJzToursShopList(jzToursShop);
        Map.put("delicacy",list);




        //路线推荐
        JzToursArticle jzToursArticle=new JzToursArticle();
        jzToursArticle.setCateId((long)1002);
        List<JzToursArticle> articles = jzToursArticleService.selectJzToursArticleList(jzToursArticle);
        JzToursShop jzToursShop1;
        list=new ArrayList<>();
        for(JzToursArticle article:articles){
            jzToursShop1=new JzToursShop();
            jzToursShop1.setId(article.getId());
            jzToursShop1.setCateId(article.getCateId());
            jzToursShop1.setCover(article.getCover());
            jzToursShop1.setName(article.getTitle());
            jzToursShop1.setIntroduce(article.getContent());
            jzToursShop1.setSubTitle(article.getSubTitle());
            list.add(jzToursShop1);
        }



        Map.put("rout",list);



        return AjaxResult.success(Map);
    }


    /***
     * 获取旅游攻略信息 （热门景点，推荐路线，旅游攻略）
     *
     *
     *
     */
     @ApiOperation("获取旅游攻略页面信息")
     @GetMapping("/getTourismStrategy")
    public AjaxResult getTourismStrategy(){

         TourismStrategyVo tourismStrategyVo;
        Map<String,List<TourismStrategyVo>> map=new HashMap<>();

         //热门景点
     JzToursShop jzToursShop=new JzToursShop();
         jzToursShop.setCateId((long)1001);
        List<JzToursShop>  shopList = jzToursShopService.selectJzToursShopList(jzToursShop);

         List<TourismStrategyVo> tourismStrategyVoList=new ArrayList<>();

         if(shopList.size()>0) {
             for (JzToursShop jzToursShop1:shopList){
                 tourismStrategyVo=new TourismStrategyVo();
                 tourismStrategyVo.setId(jzToursShop1.getId());
                 tourismStrategyVo.setCateId(jzToursShop1.getCateId());
                 tourismStrategyVo.setName(jzToursShop1.getName());
                 tourismStrategyVo.setOutId(jzToursShop1.getOutId());

                 tourismStrategyVoList.add(tourismStrategyVo);
             }

         }
         map.put("hotSpots",tourismStrategyVoList);






         //推荐路线

         JzToursArticle jzToursArticle=new JzToursArticle();
         jzToursArticle.setCateId((long)1002);
         List<JzToursArticle> articles = jzToursArticleService.selectJzToursArticleList(jzToursArticle);
         tourismStrategyVoList=new ArrayList<>();

       if(articles.size()>0){
           for(JzToursArticle jzToursArticle1:articles){
               tourismStrategyVo=new TourismStrategyVo();
               tourismStrategyVo.setId(jzToursArticle1.getId());
               tourismStrategyVo.setName(jzToursArticle1.getSubTitle());
               tourismStrategyVo.setCateId(jzToursArticle1.getCateId());
               tourismStrategyVo.setOutId(jzToursArticle1.getOutId());
               tourismStrategyVoList.add(tourismStrategyVo);

           }


       }

       map.put("recommendRout",tourismStrategyVoList);







         //路线攻略

          jzToursArticle=new JzToursArticle();
         jzToursArticle.setCateId((long)1006);
         articles = jzToursArticleService.selectJzToursArticleList(jzToursArticle);

         tourismStrategyVoList=new ArrayList<>();

         if(articles.size()>0){
             for(JzToursArticle jzToursArticle1:articles){
                 tourismStrategyVo=new TourismStrategyVo();
                 tourismStrategyVo.setId(jzToursArticle1.getId());
                 tourismStrategyVo.setName(jzToursArticle1.getTitle());
                 tourismStrategyVo.setCateId(jzToursArticle1.getCateId());
                 tourismStrategyVo.setOutId(jzToursArticle1.getOutId());
                 tourismStrategyVoList.add(tourismStrategyVo);


             }


         }

         map.put("routStrategy",tourismStrategyVoList);


      return AjaxResult.success(map);


    }


    /**
     * 查询商家信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:shop:list')")
    @ApiOperation("查询商家列表")
    @GetMapping("/shop/list")
    public TableDataInfo list(JzToursShop jzToursShop)
    {
        startPage();
        List<JzToursShop> list = jzToursShopService.selectJzToursShopList(jzToursShop);
        return getDataTable(list);
    }


    /**
     * 查询文章资讯列表
     */
    //@PreAuthorize("@ss.hasPermi('system:article:list')")
    @ApiOperation("查询文章资讯列表")
    @GetMapping("/article/list")
    public TableDataInfo list(JzToursArticle jzToursArticle)
    {
        startPage();
        List<JzToursArticle> list = jzToursArticleService.selectJzToursArticleList(jzToursArticle);
        return getDataTable(list);
    }



    /**
     * 获取文章资讯详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:article:query')")
    @ApiOperation("获取文章资讯详细信息")
    @GetMapping(value = "/article/details")
    public AjaxResult getInfo(@RequestParam("id") Long id)
    {
        return AjaxResult.success(jzToursArticleService.selectJzToursArticleById(id));
    }



    @ApiOperation("测试")
    @GetMapping(value = "/test")
    public  AjaxResult syncDataMap(){
        ScenicSpotVo scenicPointVo=new ScenicSpotVo();

        return  AjaxResult.success(feginOutService.deleteScenicSpot((long)123455667));
    }

    @ApiOperation("获取商家详情")
    @GetMapping(value = "/shop/{id}")
    public AjaxResult getShopInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jzToursShopService.selectJzToursShopById(id));
    }















}
